import React from "react";
import { useSelector } from "react-redux";
import { selectUserById } from './../features/users/usersSlice'

const PostAuthor = ({ userId }) => {
  //console.log('userId',userId)
  // const author = useSelector((state) =>
  //   state.users.find((user) => user.id === userId)
  // );

  const author = useSelector((state)=>selectUserById(state,userId))

  return <span>by {author ? author.name : "Unknown author"}</span>;
};

export default PostAuthor;